﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Xml;

namespace PSAMMatrixCloud.Common
{
    public static class LogHelper
    {
        private static ILog _DebugLoger, _InfoLoger, _ErrorLoger, _ServerLoger, _DataLoger;

        static LogHelper()
        {
            SetConfig();
            _DebugLoger = log4net.LogManager.GetLogger("DebugLoger");
            _InfoLoger = log4net.LogManager.GetLogger("InfoLoger");
            _ErrorLoger = log4net.LogManager.GetLogger("ErrorLoger");
            _ServerLoger = log4net.LogManager.GetLogger("ServerLoger");
            _DataLoger = log4net.LogManager.GetLogger("DataLoger");
        }

        private static void SetConfig()
        {
            string strConfigPath = AppDomain.CurrentDomain.BaseDirectory + @"\log4net.config";

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(strConfigPath));
        }

        /// <summary>
        /// 调试日志
        /// </summary>
        public static void Debug(string msg, Exception e = null)
        {
            _DebugLoger.Debug(msg, e);
        }

        /// <summary>
        /// 普通日志
        /// </summary>
        public static void Info(string msg, Exception e = null)
        {
            _InfoLoger.Info(msg, e);
        }

        /// <summary>
        /// 异常日志
        /// </summary>
        public static void Error(string msg, Exception e = null)
        {
            _ErrorLoger.Error(msg, e);
        }

        /// <summary>
        /// 服务器日志
        /// </summary>
        public static void Server(string msg, Exception e = null)
        {
            _ServerLoger.Info(msg, e);
        }

        public static void DataLog(string msg, Exception e = null)
        {
            _DataLoger.Debug(msg, e);
        }
    }
}
